// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//

package model

import "io"

// ComponentData is used to represent the tarball
type ComponentData interface {
	io.Reader

	// Filename is the name of tarball
	Filename() string
}

// ComponentInfo is used to update component
type ComponentInfo interface {
	ComponentData

	Standalone() *bool
	Yanked() *bool
	Hidden() *bool
	OwnerID() string
}

// PublishInfo implements ComponentInfo
type PublishInfo struct {
	ComponentData
	Stand *bool
	Yank  *bool
	Hide  *bool
	Owner string
}

// TarInfo implements ComponentData
type TarInfo struct {
	io.Reader
	Name string
}

// Filename implements ComponentData
func (ti *TarInfo) Filename() string {
	return ti.Name
}

// Filename implements ComponentData
func (i *PublishInfo) Filename() string {
	if i.ComponentData == nil {
		return ""
	}
	return i.ComponentData.Filename()
}

// Standalone implements ComponentInfo
func (i *PublishInfo) Standalone() *bool {
	return i.Stand
}

// Yanked implements ComponentInfo
func (i *PublishInfo) Yanked() *bool {
	return i.Yank
}

// Hidden implements ComponentInfo
func (i *PublishInfo) Hidden() *bool {
	return i.Hide
}

// OwnerID implements ComponentInfo
func (i *PublishInfo) OwnerID() string {
	return i.Owner
}
